//
//  GrowRecordDetailCollectionView.m
//  PigMarket
//
//  Created by mac on 2019/7/4.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "GrowRecordDetailCollectionView.h"
#import "LineLayout.h"
#import "GrowRecordDetaiCollectionViewCell.h"

@interface GrowRecordDetailCollectionView ()<UICollectionViewDelegate,UICollectionViewDataSource>
/**
 lineLayout
 */
@property (nonatomic , strong) LineLayout *lineLayout;
/**
 myCollectionView
 */
@property (nonatomic , strong) UICollectionView *myCollectionView;

@end

@implementation GrowRecordDetailCollectionView

#pragma mark - init method
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initView];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self addSubview:self.myCollectionView];
}

- (void)initLayout {
    // 布局子控件
    [self.myCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
}
#pragma mark - delegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataArr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    GrowRecordDetaiCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"GrowRecordDetaiCollectionViewCell" forIndexPath:indexPath];
    [cell.img sd_setImageWithURL:[NSURL URLWithString:self.dataArr[indexPath.item]] placeholderImage:[UIImage imageNamed:@"placeholder_middle"]];
    return cell;
}
#pragma mark - getter and setter
- (void)setDataArr:(NSArray *)dataArr {
    _dataArr = dataArr;
    [self.myCollectionView reloadData];
}
- (LineLayout *)lineLayout {
    if (!_lineLayout) {
        _lineLayout = [[LineLayout alloc] init];
        _lineLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        _lineLayout.itemSize = CGSizeMake(260, 145);
        _lineLayout.minimumInteritemSpacing = 10;
        
    }
    return _lineLayout;
}
- (UICollectionView *)myCollectionView {
    if (!_myCollectionView) {
        _myCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:self.lineLayout];
        [_myCollectionView registerClass:[GrowRecordDetaiCollectionViewCell class] forCellWithReuseIdentifier:@"GrowRecordDetaiCollectionViewCell"];
        _myCollectionView.backgroundColor = [UIColor whiteColor];
        _myCollectionView.delegate = self;
        _myCollectionView.dataSource = self;
        _myCollectionView.showsHorizontalScrollIndicator = NO;
    }
    return _myCollectionView;
}
@end
